Skip to content

Collections: Customizable collection names#878

Merged
Ayush8923 merged 5 commits into
mainfrom
fix/added-field-collection
May 22, 2026
Merged

Collections: Customizable collection names#878
Ayush8923 merged 5 commits into
mainfrom
fix/added-field-collection

Conversation

@Ayush8923
Copy link
Copy Markdown
Collaborator

@Ayush8923 Ayush8923 commented May 22, 2026

Issue: ProjectTech4DevAI/kaapi-frontend#172

Summary

  • In the Collection API responses now include optional name and description fields, providing more detailed collection information in public endpoints.
  • Create the Edit collection api in which we can update the collection name and their description.
  • Added tests covering successful, partial, conflict, and not-found update scenarios.

Checklist

Before submitting a pull request, please ensure that you mark these task.

  • Ran fastapi run --reload app/main.py or docker compose up in the repository root and test.
  • If you've fixed a bug or added code that is tested and has test cases.

@Ayush8923 Ayush8923 self-assigned this May 22, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

📝 Walkthrough

Walkthrough

Adds PATCH /collections/{collection_id} using a new CollectionUpdate model; extends CollectionPublic with optional name and description; updates to_collection_public to include those fields; implements CollectionCrud.update with name-uniqueness and IntegrityError handling; adds docs, re-export, and API/CRUD tests.

Changes

Collection update flow

Layer / File(s) Summary
Models: add CollectionUpdate and extend CollectionPublic
backend/app/models/collection.py
Adds CollectionUpdate with optional name and description; extends CollectionPublic to include optional name and description.
Helper: populate name/description in to_collection_public
backend/app/services/collections/helpers.py
to_collection_public() now sets name and description from the source Collection in both vector-store and non-vector-store branches.
CRUD: add CollectionCrud.update implementation
backend/app/crud/collection/collection.py
Adds update(collection_id, patch) that applies non-null patch fields, validates project-wide name uniqueness (409 on conflict), updates updated_at, persists changes, and maps IntegrityError to 409.
API route: import model and add PATCH /{collection_id}
backend/app/api/routes/collections.py
Imports CollectionUpdate and adds update_collection PATCH route requiring project permission, calling CollectionCrud.update, and returning CollectionPublic.
Docs and re-export
backend/app/api/docs/collections/update.md, backend/app/models/__init__.py
Adds documentation describing editable fields and behavior for the update endpoint; re-exports CollectionUpdate from models package.
API tests for PATCH /collections/{id}
backend/app/tests/api/routes/collections/test_collection_update.py
Adds FastAPI tests covering success, partial update, duplicate-name 409, and 404 for missing collection.
CRUD tests for CollectionCrud.update
backend/app/tests/crud/collections/collection/test_crud_collection_update.py
Adds unit tests covering name+description updates, name-only updates, no-op rename, name-conflict 409, 404, and IntegrityError race handling.
sequenceDiagram
  participant Client
  participant API as update_collection route
  participant Crud as CollectionCrud.update
  participant DB as Database
  participant Helper as to_collection_public

  Client->>API: PATCH /collections/{id} with CollectionUpdate
  API->>Crud: CollectionCrud.update(collection_id, patch)
  Crud->>DB: load collection / persist changes
  Crud->>Helper: to_collection_public(updated_collection)
  Helper->>API: CollectionPublic
  API->>Client: 200 OK with CollectionPublic
Loading

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels: enhancement

Suggested reviewers:

  • vprashrex
  • kartpop

"I hopped through code with nibbling delight,
Name and description now appear in sight.
Patch, CRUD, helper—each in a row,
Docs and export make the change glow.
A rabbit's cheer for updates—soft and light!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.75% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main feature added: the ability to customize collection names through a new PATCH endpoint and related model updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/added-field-collection

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sentry
Copy link
Copy Markdown

sentry Bot commented May 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/app/api/routes/collections.py`:
- Around line 211-234: The update_collection function is missing an explicit
return type; add a return type hint (e.g., -> APIResponse) to the
update_collection signature to reflect that it returns
APIResponse.success_response(...), and if APIResponse is not already imported in
backend/app/api/routes/collections.py, add the appropriate import; keep the
existing parameter annotations and ensure the signature uses the exact function
name update_collection and the same parameters (session: SessionDep,
current_user: AuthContextDep, patch: CollectionUpdate, collection_id: UUID =
FastPath(...)).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f6747a73-5f99-43f4-8f5a-0f72b5e39d52

📥 Commits

Reviewing files that changed from the base of the PR and between 3fbd9e1 and f099b15.

📒 Files selected for processing (5)
  • backend/app/api/docs/collections/update.md
  • backend/app/api/routes/collections.py
  • backend/app/crud/collection/collection.py
  • backend/app/models/__init__.py
  • backend/app/models/collection.py
✅ Files skipped from review due to trivial changes (1)
  • backend/app/api/docs/collections/update.md

Comment thread backend/app/api/routes/collections.py
Comment thread backend/app/crud/collection/collection.py
description: str | None = Field(
default=None,
description="Description of the collection",
)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add testcases for this as well

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, added the testcases.


class CollectionPublic(SQLModel):
id: UUID
name: str | None = Field(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while this is fine can we add some restriction like name should be there instead of name and minimum and maximum length

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the code accordingly.

Comment on lines +104 to +107
raise HTTPException(
status_code=409,
detail=f"Collection '{changes['name']}' already exists. Choose a different name.",
)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you check other code, usually HTTPException belongs in routes, not crud/

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check this again.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
backend/app/tests/api/routes/collections/test_collection_update.py (1)

13-91: ⚖️ Poor tradeoff

Consider using factory pattern for test data creation.

Similar to the CRUD tests, these API tests use helper functions get_project() and get_assistant_collection() rather than the factory pattern. As per coding guidelines, test fixtures in backend/app/tests/ should use the factory pattern.

As per coding guidelines: Use factory pattern for test fixtures in backend/app/tests/.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/app/tests/api/routes/collections/test_collection_update.py` around
lines 13 - 91, These API tests (test_update_collection_returns_updated_fields,
test_update_collection_partial_update_preserves_other_fields,
test_update_collection_rename_to_existing_name_returns_409,
test_update_collection_not_found_returns_404) use helper functions get_project()
and get_assistant_collection(); update them to follow the repository guideline
by using the factory pattern instead: import and use the appropriate
ProjectFactory and CollectionFactory (or equivalent factories used in CRUD
tests) to create projects and collections in each test, replace calls to
get_project() and get_assistant_collection() with factory.create(...) (or the
factory's create/ build API), and remove reliance on those helpers so fixtures
align with backend/app/tests/ conventions while keeping the same test
assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@backend/app/tests/api/routes/collections/test_collection_update.py`:
- Around line 13-91: These API tests
(test_update_collection_returns_updated_fields,
test_update_collection_partial_update_preserves_other_fields,
test_update_collection_rename_to_existing_name_returns_409,
test_update_collection_not_found_returns_404) use helper functions get_project()
and get_assistant_collection(); update them to follow the repository guideline
by using the factory pattern instead: import and use the appropriate
ProjectFactory and CollectionFactory (or equivalent factories used in CRUD
tests) to create projects and collections in each test, replace calls to
get_project() and get_assistant_collection() with factory.create(...) (or the
factory's create/ build API), and remove reliance on those helpers so fixtures
align with backend/app/tests/ conventions while keeping the same test
assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 664e3b2c-41f7-4cc8-ace1-81b6d3b4ea31

📥 Commits

Reviewing files that changed from the base of the PR and between f099b15 and 3f84995.

📒 Files selected for processing (4)
  • backend/app/api/routes/collections.py
  • backend/app/crud/collection/collection.py
  • backend/app/tests/api/routes/collections/test_collection_update.py
  • backend/app/tests/crud/collections/collection/test_crud_collection_update.py

@Ayush8923 Ayush8923 requested a review from AkhileshNegi May 22, 2026 05:57
collection_crud = CollectionCrud(session, current_user.project_.id)
try:
collection = collection_crud.update(collection_id, patch)
except CollectionNameConflictError as err:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Nitpick) If there is an error at the crud layer we can raise the httpexception at crud file only .. no need of raising httpexception here..

Copy link
Copy Markdown
Collaborator Author

@Ayush8923 Ayush8923 May 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check this comment #878 (comment). Earlier, I added the httpexception at crub file. But then I change the code according to comment.

@Ayush8923 Ayush8923 merged commit 5888b7e into main May 22, 2026
3 checks passed
@Ayush8923 Ayush8923 deleted the fix/added-field-collection branch May 22, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants